var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { signal, gdclass } from "../decorators";
let BaseMove = class BaseMove extends godot.Node2D {
    constructor() {
        super(...arguments);
        this.x = 200;
        this.y = 200;
        this.xv = 3;
        this.yv = 3;
        this.face = 0; // 0 1 2 3 4 不变 上,下,左,右
        this.isAutoMove = false;
        this.isControlMove = false;
        this.isInputMove = false;
    }
    _process(delta) {
        if (this.get_parent() == null) {
            return;
        }
        if (this.isAutoMove) {
            if (this.x < 800) {
                this.x = this.x + this.xv;
            }
            else {
                this.x = 200;
            }
            this.updatePosition();
        }
        if (this.isInputMove) {
            this.handleInput();
        }
    }
    _input(event) {
        if (this.get_parent() == null) {
            return;
        }
        // is_pressed() 按下触发 否则触发2次,按下与释放都会触发
        if (this.isControlMove && event.is_pressed()) {
            this.handEvent(event);
        }
    }
    handleInput() {
        this.face = 0;
        if (godot.Input.is_key_pressed(godot.KEY_D)) {
            this.face = 4;
            this.x = this.x + this.xv;
        }
        else if (godot.Input.is_key_pressed(godot.KEY_A)) {
            this.face = 3;
            this.x = this.x - this.xv;
        }
        else if (godot.Input.is_key_pressed(godot.KEY_W)) {
            this.face = 1;
            this.y = this.y - this.yv;
        }
        else if (godot.Input.is_key_pressed(godot.KEY_S)) {
            this.face = 2;
            this.y = this.y + this.yv;
        }
        else if (godot.Input.is_mouse_button_pressed(godot.BUTTON_LEFT)) {
            let pos = this.get_viewport().get_mouse_position();
            this.x = pos.x;
            this.y = pos.y;
        }
        this.updatePosition();
        // 发送信号
        this.emit_signal("OnUpdatePos", this.face);
    }
    handEvent(event) {
        if (event instanceof godot.InputEventKey) {
            if (event.scancode == godot.KEY_D) {
                this.x = this.x + this.xv;
            }
            else if (event.scancode == godot.KEY_A) {
                this.x = this.x - this.xv;
            }
            else if (event.scancode == godot.KEY_W) {
                this.y = this.y - this.yv;
            }
            else if (event.scancode == godot.KEY_S) {
                this.y = this.y + this.yv;
            }
        }
        else if (event instanceof godot.InputEventMouseButton) {
            if (event.button_index == godot.BUTTON_LEFT) {
                this.x = event.position.x;
                this.y = event.position.y;
            }
        }
        this.updatePosition();
    }
    updatePosition() {
        if (this.get_parent() instanceof godot.Node2D) {
            this.get_parent().position = new godot.Vector2(this.x, this.y);
        }
    }
};
__decorate([
    signal
], BaseMove, "OnUpdatePos", void 0);
BaseMove = __decorate([
    gdclass
], BaseMove);
export default BaseMove;
//# sourceMappingURL=base_move.jsx.map